Skip to content

Conversation

FieteO
Copy link
Contributor

@FieteO FieteO commented May 10, 2025

What's changed?

This PR adds a new org.openrewrite.apache.httpclient5.MigrateStringEntity recipe that migrates StringEntity.setContentEncoding(..).

What's your motivation?

Anything in particular you'd like reviewers to focus on?

Draft, still at an early stage. I am getting an AssertionError when running the test:

java.lang.AssertionError: [Recipe validation must have no failures] 
Expecting empty but was: [[Invalid{property='org.openrewrite.apache.httpclient5.MigrateStringEntity', value='null', message='Recipe class org.openrewrite.apache.httpclient5.MigrateStringEntity cannot be found'},

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

Any additional context

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite May 10, 2025
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions could not be made:

  • src/main/resources/META-INF/rewrite/examples.yml
    • lines 703-702
    • lines 749-771

@EqualsAndHashCode(callSuper = false)
public class MigrateStringEntity extends Recipe {

private static final String METHOD_PATTERN = "org.apache.http.entity.StringEntity setContentEncoding(..)";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be "org.apache.http.entity.AbstractHttpEntity setContentEncoding(..)" instead, as the method you're trying to target belongs the the parent class rather than to StringEntity

timtebeek and others added 3 commits May 29, 2025 16:15
Comment on lines +56 to +63
if ("ANY".equals(f.getSimpleName()) && TypeUtils.isOfClassType(f.getTarget().getType(), "org.apache.hc.client5.http.auth.AuthScope")) {
maybeAddImport("org.apache.hc.client5.http.auth.AuthScope");
return JavaTemplate.builder("new AuthScope(null, -1)")
.imports("org.apache.hc.client5.http.auth.AuthScope")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "httpcore5"))
.build()
.apply(updateCursor(f), f.getCoordinates().replace());
}
Copy link
Contributor

@steve-aom-elliott steve-aom-elliott May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is implementation copied from the MigrateAuthScope recipe here, correct? I think perhaps rather than using visitFieldAccess(..) you might want to take a look at visitVariableDeclaration(..) or visitNewClass(..) for getting to the existing assignment of a new StringEntity(..) to a variable and visitMethodInvocation(..) for getting to the calling of setEncoding(..).

You might also find the RemoveMethodInvocationsVisitor useful for getting rid of the setEncoding(..)

Copy link
Contributor

github-actions bot commented Sep 1, 2025

This PR is stale because it has been open for 90 days with no activity. Remove stale label or comment or this will be closed in two weeks. PRs may be reopened when there is renewed interest.

@github-actions github-actions bot added the Stale label Sep 1, 2025
@github-actions github-actions bot closed this Sep 22, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Apache HttpClient 4 to 5 does not yet migrate StringEntity.setContentEncoding() to constructor argument
3 participants